using System;
using System.Collections.Generic;
using UnityEngine;

namespace GraphEditor.Runtime
{
    // 这里的数据放在这里是为了方便GraphBlueprint类里面处理多态序列化的。
    // 但实际上是Editor下的数据，用UNITY_EDITOR宏包裹，也是为了避免在构建的时候打到包里去。
#if UNITY_EDITOR

    /// <summary>
    /// 图的视图数据
    /// </summary>
    [Serializable]
    public class GraphData
    {
        /// <summary>
        /// 当前图的唯一标识
        /// </summary>
        public string id;
        /// <summary>
        /// 图的标题
        /// </summary>
        public string title;
        /// <summary>
        /// 缩放系数delta值
        /// </summary>
        public float zoomDelta = 0.25f;
        /// <summary>
        /// 缩放系数最大值
        /// </summary>
        public float zoomMax = 1f;
        /// <summary>
        /// 缩放系数最小值
        /// </summary>
        public float zoomMin = 0.1f;
        /// <summary>
        /// 缩放系数
        /// </summary>
        public float zoomLevel = 1f;
        /// <summary>
        /// 平移值
        /// </summary>
        public Vector2 offset;
        /// <summary>
        /// 所有的节点对象
        /// </summary>
        public List<NodeData> nodes = new();
        /// <summary>
        /// 所有的连线对象
        /// </summary>
        public List<EdgeData> edges = new();
        /// <summary>
        /// 所有的分组对象（分组的作用只是包裹住一批节点，并提供折叠功能）
        /// </summary>
        public List<GroupData> groups = new();
    }

    /// <summary>
    /// 节点的视图数据
    /// </summary>
    [Serializable]
    public class NodeData
    {
        /// <summary>
        /// 节点唯一标识
        /// </summary>
        public string id;
        /// <summary>
        /// 节点位置
        /// </summary>
        public Vector2 position;
        /// <summary>
        /// 该节点里的所有端口
        /// </summary>
        public List<PortData> ports = new();
    }

    /// <summary>
    /// 连线的视图数据
    /// </summary>
    [Serializable]
    public class EdgeData
    {
        /// <summary>
        /// 连线的唯一标识
        /// </summary>
        public string id;
        /// <summary>
        /// 起始端口的唯一标识
        /// </summary>
        public string fromId;
        /// <summary>
        /// 目标端口的唯一标识
        /// </summary>
        public string toId;
    }

    /// <summary>
    /// 端口的视图数据
    /// </summary>
    [Serializable]
    public class PortData
    {
        /// <summary>
        /// 端口唯一标识
        /// </summary>
        public string id;
    }

    /// <summary>
    /// 分组的视图数据
    /// </summary>
    [Serializable]
    public class GroupData
    {
        /// <summary>
        /// 分组的唯一标识
        /// </summary>
        public string id;
        /// <summary>
        /// 标题
        /// </summary>
        public string title;
        /// <summary>
        /// 区域大小
        /// </summary>
        public Rect rect;
        /// <summary>
        /// 颜色
        /// </summary>
        public Color color;
        /// <summary>
        /// 自动适配区域
        /// </summary>
        public bool autoSize;
        /// <summary>
        /// 文本注释
        /// </summary>
        public string notes;
    }
#endif
}